package com.mall.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.entity.OrderItem;
import com.mall.mapper.OrderItemMapper;
import com.mall.service.IOrderItemService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author ShouPeng
 * @since 2024-01-17
 * 订单商品服务实现类
 */
@Service
public class OrderItemServiceImpl implements IOrderItemService {
    final
    OrderItemMapper orderItemMapper;

    public OrderItemServiceImpl(OrderItemMapper orderItemMapper) {
        this.orderItemMapper = orderItemMapper;
    }

    /**
     * 查询订单包含的商品
     * @param page 页
     * @return list
     */
    @Override
    public IPage<OrderItem> queryOrderItem(Page<OrderItem> page,Integer orderId) {
        return orderItemMapper.selectPage(page,new QueryWrapper<OrderItem>().eq("order_id",orderId));
    }

    /**
     * 查询订单包含的商品
     * @param orderId
     * @return list
     */
    @Override
    public List<Map<String,Object>> queryOrderItemById(Integer orderId) {
        return orderItemMapper.queryOrderItemById(orderId);
    }

    /**
     * @param orderId
     * @return list
     */
    @Override
    public int deleteOrderItemByOrderId(Integer orderId) {
        return orderItemMapper.delete(new QueryWrapper<OrderItem>().eq("order_id",orderId));
    }


    /**
     * 删除订单包含的商品
     *
     * @param ids ids
     * @return success count
     */
    @Override
    public Integer deleteOrderItem(List<String> ids) {
        return orderItemMapper.deleteBatchIds(ids);
    }

    /**
     * 修改订单包含的商品
     *
     * @param orderItem entity
     * @return bool
     */
    @Override
    public Boolean updateOrderItem(OrderItem orderItem) {
        return orderItemMapper.updateById(orderItem) > 0;
    }

    /**
     * 添加订单包含的商品
     * @param orderItem entity
     * @return bool
     */
    @Override
    public Boolean addOrderItem(OrderItem orderItem) {
        return orderItemMapper.insert(orderItem) > 0;
    }
}
